home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / wwbbs31_source.lha / WWBBS / WWBBSSrc / node_frontend.c < prev    next >
C/C++ Source or Header  |  1995-06-25  |  3KB  |  122 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <libraries/wwbbs.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #include "wwbbs.h"
  10.  
  11. #include "wwbbs_settings.h"
  12.  
  13. #include "wwbbs_lib.h"
  14.  
  15. #include "node_lib.h"
  16.  
  17. #include "libs.h"
  18.  
  19. #include "Data:Programs/Include/wwbbs_commands.h"
  20.  
  21. LONG __saveds NodeFrontEndProc()
  22.     {
  23.         struct ConfirmationMessage *msg;
  24.         struct CommandMessage *qmsg=NULL;
  25.         struct Process *proc;
  26.         proc=(struct Process *) FindTask(NULL);
  27.         WaitPort(&proc->pr_MsgPort);
  28.         if(msg=(struct ConfirmationMessage *) GetMsg(&proc->pr_MsgPort))
  29.             {
  30.                 BYTE name[64],frontend_name[64],id[33];
  31.                 struct MsgPort *port,*frontend_port;
  32.                 BOOL ok=TRUE;
  33.                 strcpy(id,msg->cm_ID);
  34.                 sprintf(name,"WWBBS Node.%s",id);
  35.                 sprintf(frontend_name,"WWBBS Front End.%s",id);
  36.                 if(!(port=CreatePort(name,0)))
  37.                     ok=FALSE;
  38.                 if(!(frontend_port=CreatePort(frontend_name,0)))
  39.                     ok=FALSE;
  40.                 msg->cm_Return=ok;
  41.                 ReplyMsg((struct Message *) msg);
  42.                 if(ok)
  43.                     {
  44.                         struct Libraries *libs;
  45.                         if(libs=OpenLibraries())
  46.                             {
  47.                                 BOOL node_autobaud=FALSE;
  48.                                 GetConfigTags(CFGTAG_Path,"Nodes",CFGTAG_Name,id,NDTAG_AutoBaud,&node_autobaud,TAG_END);
  49.                                 if(StartProcess("WWBBS Serial",SerialProc,20000,id))
  50.                                     {
  51.                                         BOOL kg=TRUE;
  52.                                         while(kg)
  53.                                             {
  54.                                                 Wait( (1 << port->mp_SigBit) | (1 << frontend_port->mp_SigBit) );
  55.                                                 {
  56.                                                     struct CommandMessage *msg;
  57.                                                     ULONG data;
  58.                                                     while(kg && (msg=(struct CommandMessage *) GetMsg(port)))
  59.                                                         {
  60.                                                             data=msg->cm_Data;
  61.                                                             msg->cm_Data=NULL;
  62.                                                             switch(msg->cm_Command)
  63.                                                                 {
  64.                                                                     case NDCMD_Quit:
  65.                                                                         msg->cm_Data=TRUE;
  66.                                                                         qmsg=msg;
  67.                                                                         kg=FALSE;
  68.                                                                         break;
  69.                                                                 }
  70.                                                             if(!qmsg)
  71.                                                                 ReplyMsg((struct Message *) msg);
  72.                                                         }
  73.                                                 }
  74.                                                 {
  75.                                                     struct CommandMessage *msg;
  76.                                                     ULONG data;
  77.                                                     while(kg && (msg=(struct CommandMessage *) GetMsg(frontend_port)))
  78.                                                         {
  79.                                                             data=msg->cm_Data;
  80.                                                             msg->cm_Data=NULL;
  81.                                                             switch(msg->cm_Command)
  82.                                                                 {
  83.                                                                     case NDCMD_Session:
  84.                                                                         {
  85.                                                                             ULONG baud=0;
  86.                                                                             {
  87.                                                                                 struct TagItem *tag;
  88.                                                                                 if(tag=FindTagItem(NDSESSIONTAG_Baud,(struct TagItem *) data))
  89.                                                                                     baud=(ULONG) tag->ti_Data;
  90.                                                                             }
  91.                                                                             if(SerialCommand(id,SERCMD_Open,TAG_END))
  92.                                                                                 {
  93.                                                                                     if(node_autobaud && baud)
  94.                                                                                         SerialCommandTags(id,SERCMD_SetBaud,SERSETBAUDTAG_NewBaud,baud,TAG_END);
  95.                                                                                     Session(libs,id,FALSE,baud);
  96.                                                                                     SerialCommand(id,SERCMD_Close,TAG_END);
  97.                                                                                 }
  98.                                                                         }
  99.                                                                         msg->cm_Data=TRUE;
  100.                                                                         break;
  101.                                                                 }
  102.                                                             if(!qmsg)
  103.                                                                 ReplyMsg((struct Message *) msg);
  104.                                                         }
  105.                                                 }
  106.                                             }
  107.                                         KillProcess("WWBBS Serial",id);
  108.                                     }
  109.                                 CloseLibraries(libs);
  110.                             }
  111.                         DeletePort(frontend_port);
  112.                         DeletePort(port);
  113.                     }
  114.             }
  115.         if(qmsg)
  116.             {
  117.                 Forbid();
  118.                 ReplyMsg((struct Message *) qmsg);
  119.             }
  120.         return(0);
  121.     }
  122.